exports.add=[{
	 _type:"model_methods",
	_config: {name:"Spreadsheet"},
	
	AfterNewCustom: function() {
		this.GenerateFID();
	},

	GenerateFID: function() {
		if (this.fid) return;
		if (!this.generator) return;
		var rr=this.GetRR();
		this.fid=rr.site.sql.execute_and_fetch_one("spreadsheets/max_fid_of_generator",this).fid+1;
	},

	AddWorksheet: function() {
		if (!this.id) this.SaveAll();
		var rr=this.GetRR();
		var ws=rr.site.models.Worksheet.Create();
		ws.spreadsheet_id=this.id;
		var cnt=rr.site.sql.execute_and_fetch_one("worksheets/count_of_spreadsheet",this).cnt+1;
		ws.name="New worksheet "+cnt;
		ws.SaveAll();
		return ws;
	}
}];


